window.M_ECharts_EndTime = "";
window.M_ECharts_StartTime = "";
window.M_ECharts_Project = "all";
$(function() {
	// 通过屏幕大小获得自适应参数 所有echart 字体大小*参数
	myRsLayoutAllEcharts(false);
	var pre = new Date();
	pre.setFullYear(pre.getFullYear() - 1);
	var now = new Date();
	M_ECharts_StartTime = pre.Format("yyyy-MM-dd");
	M_ECharts_EndTime = now.Format("yyyy-MM-dd");
	setCollectionTitle(M_ECharts_StartTime + " 至 " + M_ECharts_EndTime
			+ " 所有的项目");
	getAllEchart();
	setTimeout(function() {
		myRsLayoutAllEcharts(true);
	}, 100);
});


function setCollectionTitle(text) {
	$("#collection-title").text(text);
}

function getAllEchart() {
	gettitle();
	getscatter();
	getsankey();
	getbar();
	getpie();
}

function gettitle() {
	$.ajax({
		type : "post",
		url : $('body').attr('ctxPath') + '/report/visualization/getTitle',
		data : "&startTime=" + M_ECharts_StartTime + "&endTime=" + M_ECharts_EndTime + "&project=" + M_ECharts_Project,
		dataType : "json",
		success : function(result) {
			if (result.state) {
				var data=result.data;
				$("#title-plan").text(data.plan);
				$("#title-materiel").text(data.materiel);
				$("#title-packingList").text(data.packingList);
			} else {
				layer.alert(data.msg);
			}
		},
		error : function() {
			console.log("网络错误，获取标题数据失败！");
		}
	});
}

function myRsLayoutAllEcharts(reload) {
	var myRsLayoutHeight = $(window).height();
	var header = $("#myRsLayout-navbar-header").outerHeight(true);
	var breadcrumb = $("#myRsLayout-breadcrumb").outerHeight(true);
	$("#scatter").height((myRsLayoutHeight - header - breadcrumb) * 0.85 * 0.68);
	$("#sankey").height((myRsLayoutHeight - header - breadcrumb) * 0.85 * 0.32);
	$("#bar").height((myRsLayoutHeight - header - breadcrumb) * 0.85 * 0.55);
	$("#pie").height((myRsLayoutHeight - header - breadcrumb) * 0.85 * 0.45);
	var left = $("#content-left").outerHeight(true);
	var right = $("#content-right").outerHeight(true);
	var fix=Number(left)-Number(right);
	$("#bar").height(Number($("#bar").height())+fix*0.5);
	$("#pie").height(Number($("#pie").height())+fix*0.5);
	if (reload) {
		scatter.resize();
		sankey.resize();
		bar.resize();
		pie.resize();
	}

}


window.onresize = function() {
	setTimeout(function() {
		myRsLayoutAllEcharts(true);
	}, 100);
}